package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.TariffDao;
import com.mstore.pojo.Tariff;

public class TariffService {

	private TariffDao tariffDao;

	/**
	 * 查看资费表
	 */
	public List<Tariff> watchAllTariff() {
		List<Tariff> tariffs = new ArrayList<Tariff>();
		List<Object> objects = tariffDao.watchAllTariff();
		for (Object object : objects) {
			tariffs.add((Tariff) object);
		}
		return tariffs;
	}

	public Tariff FindById(long tariffid) {
		return tariffDao.FindById(tariffid);
	}

	/**
	 * 通过id查询资费表(查有效的)
	 */
	public Tariff watchTariffById(Long tariffId) {
		List<Tariff> tariffs = new ArrayList<Tariff>();
		List<Object> objects = tariffDao.watchTariffById(tariffId);
		for (Object object : objects) {
			tariffs.add((Tariff) object);
		}
		if (tariffs != null && tariffs.size() > 0) {
			return tariffs.get(0);
		}
		return null;
	}

	public boolean save(Tariff tariff) {
		return tariffDao.save(tariff);
	}

	public List<Tariff> getList(Tariff tariff, int index) {

		List<Tariff> tariffs = new ArrayList<Tariff>();
		List<Object> objects = tariffDao.getList(tariff, index);

		for (Object object : objects) {
			Tariff tar = (Tariff) object;
			tar.setCreateDate(tar.getCreateDate().substring(0,
					tar.getCreateDate().indexOf(".")));
			tariffs.add(tar);
		}
		return tariffs;

	}

	public int getCount() {
		return tariffDao.getCount();
	}

	public boolean Delete(Tariff tariff) {
		return tariffDao.Delete(tariff);
	}

	/**
	 * 通过GoodsId查询资费信息 * @param GoodsId
	 */
	public Tariff getTariffByGoodsId(Long GoodsId) {
		Object obj = tariffDao.getTariffByGoodsId(GoodsId);
		return obj == null ? null : (Tariff) obj;
	}

	public TariffDao getTariffDao() {
		return tariffDao;
	}

	public void setTariffDao(TariffDao tariffDao) {
		this.tariffDao = tariffDao;
	}

}
